825. 适龄的朋友
为保证权益,题目请参考 825. 适龄的朋友(From LeetCode).
解决方案1
Python
python
class Solution:
def numFriendRequests(self, ages: List[int]) -> int:
n = len(ages)
ages.sort()
left = right = ans = 0
for age in ages:
if age < 15:
continue
while ages[left] <= 0.5 * age + 7:
left += 1
while right + 1 < n and ages[right + 1] <= age:
right += 1
ans += right - left
return ans
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14